﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
    <xs:element name="AcceleratorApplication">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="role" maxOccurs="1" minOccurs="0">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="applications" type="xs:string" />
                            <xs:element name="roleRoot">
                                <xs:complexType>
                                    <xs:attribute name="pathKey" type="xs:string" use="required" />
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="appRoot">
                                <xs:complexType>
                                    <xs:attribute name="pathKey" type="xs:string" use="required" />
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="diagnoticsStorage">
                                <xs:complexType>
                                    <xs:attribute name="pathKey" type="xs:string" use="required" />
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="localStorage">
                                <xs:complexType>
                                    <xs:attribute name="pathKey" type="xs:string" use="required" />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="version" type="xs:string" use="optional" />
                        <xs:attribute name="name" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="application" maxOccurs="unbounded" minOccurs="1">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="params" minOccurs="0" type="Params" />
                            <xs:element name="variables" minOccurs="0" type="Variables" />
                            <xs:element name="dependencies" minOccurs="0" type="Dependencies" />
                            <xs:element name="configuration" minOccurs="0" type="Config" />
                            <xs:element name="runtime" minOccurs="0" type="Runtime" />
                        </xs:sequence>
                        <xs:attributeGroup ref="ApplicationReferenceAttributes" />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="elementFormDefault" type="xs:string" use="required" />
            <xs:attribute name="attributeFormDefault" type="xs:string" use="required" />
            <xs:attribute name="serviceDefinitionFile" type="xs:string" use="optional" default="ServiceDefinition.csdef" />
            <xs:attribute name="serviceConfigurationFile" type="xs:string" use="optional" default="ServiceConfiguration.cscfg" />
        </xs:complexType>
    </xs:element>
    <xs:complexType name="Params">
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
            <xs:element name="param">
                <xs:complexType>
                    <xs:attribute name="key" type="xs:string" use="required" />
                    <xs:attribute name="value" type="xs:string" use="optional" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Variables">
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
            <xs:element name="variable">
                <xs:complexType>
                    <xs:attribute name="key" type="xs:string" use="required" />
                    <xs:attribute name="value" type="xs:string" use="optional" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:attributeGroup name="ApplicationReferenceAttributes">
        <xs:attribute name="name" type="xs:string" use="required" />
        <xs:attribute name="version" type="xs:string" use="optional" />
        <xs:attribute name="description" default="" type="xs:string" use="optional" />
    </xs:attributeGroup>
    <xs:complexType name="ApplicationReference">
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
            <xs:element name="application">
                <xs:complexType>
                    <xs:attributeGroup ref="ApplicationReferenceAttributes" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Dependencies">
        <xs:sequence>
            <xs:element name="applications" type="ApplicationReference" minOccurs="0" />
            <xs:element name="localResources" minOccurs="0" type="Resources" />
            <xs:element name="validation" minOccurs="0" type="Validation" />
            <xs:element name="localCopy" minOccurs="0" type="LocalCopy" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Config">
        <xs:sequence>
            <xs:element name="files" minOccurs="0">
                <xs:complexType>
                    <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="file">
                            <xs:complexType>
                                <xs:sequence maxOccurs="unbounded" minOccurs="0">
                                    <xs:choice>
                                        <xs:element name="loadVariable" type="LoadVariable" />
                                        <xs:element name="replace" type="Replace" />
                                        <xs:element name="regex" type="RegExReplace" />
                                    </xs:choice>
                                </xs:sequence>
                                <xs:attribute name="enabled" type="xs:boolean" use="optional" default="true" />
                                <xs:attribute name="path" type="xs:string" use="required" />
                                <xs:attribute name="logging" default="false" type="xs:boolean" use="optional" />
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="environmentVariables" maxOccurs="1" minOccurs="0" type="EnvironmentVariables" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="EnvironmentVariables">
        <xs:sequence>
            <xs:element name="environmentVariable" maxOccurs="unbounded" minOccurs="0" type="EnvironmentVariable" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="EnvironmentVariable">
        <xs:attribute name="enabled" type="xs:boolean" use="optional" default="true" />
        <xs:attribute name="name" type="xs:string" use="required" />
        <xs:attribute name="value" type="xs:string" use="required" />
        <xs:attribute name="evalEnvironmentVariablesInReplacement" default="true" type="xs:boolean" use="optional" />
    </xs:complexType>
    <xs:complexType name="Replace">
        <xs:attribute name="enabled" type="xs:boolean" use="optional" default="true" />
        <xs:attribute name="pattern" type="xs:string" use="required" />
        <xs:attribute name="replacement" type="xs:string" use="required" />
        <xs:attribute name="evalVariablesInPattern" type="xs:boolean" use="required" />
        <xs:attribute name="evalVariablesInReplacement" type="xs:boolean" use="required" />
        <xs:attribute name="evalVariablesInMatch" type="xs:boolean" use="optional" />
        <xs:attribute name="replacePathChar" type="xs:string" use="optional" />
    </xs:complexType>
    <xs:complexType name="RegExReplace">
        <xs:attribute name="enabled" type="xs:boolean" use="optional" default="true" />
        <xs:attribute name="pattern" type="xs:string" use="required" />
        <xs:attribute name="explicitCapture" default="false" type="xs:boolean" use="optional" />
        <xs:attribute name="evalVariablesInMatch" default="true" type="xs:boolean" use="optional" />
        <xs:attribute name="replacePathChar" type="xs:string" use="optional" />
        <xs:attribute name="replacement" default="true" type="xs:string" use="optional" />
        <xs:attribute name="evalVariablesInPattern" default="true" type="xs:boolean" use="optional" />
        <xs:attribute name="evalVariablesInReplacement" default="true" type="xs:boolean" use="optional" />
    </xs:complexType>
    <xs:complexType name="LoadVariable">
        <xs:attribute name="enabled" type="xs:boolean" use="optional" default="true" />
        <xs:attribute name="pattern" type="xs:string" use="required" />
        <xs:attribute name="overwriteExistingVariables" default="true" type="xs:boolean" use="optional" />
        <xs:attribute name="evalVariablesInPattern" default="true" type="xs:boolean" use="optional" />
        <xs:attribute name="evalVariablesInReplacement" default="true" type="xs:boolean" use="optional" />
        <xs:attribute name="evalVariablesInMatch" default="true" type="xs:boolean" use="optional" />
    </xs:complexType>
    <xs:complexType name="Runtime">
        <xs:sequence>
            <xs:element name="onStart" minOccurs="0">
                <xs:complexType mixed="true">
                    <xs:sequence>
                        <xs:element name="process" maxOccurs="unbounded" minOccurs="0" type="ProcessType" />
                        <xs:element name="webServer" maxOccurs="1" minOccurs="0" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="onRunning" minOccurs="0">
                <xs:complexType>
                    <xs:sequence minOccurs="0">
                        <xs:element name="process" maxOccurs="unbounded" minOccurs="0" type="ProcessType" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="onStop" minOccurs="0">
                <xs:complexType>
                    <xs:sequence minOccurs="0">
                        <xs:element name="process" maxOccurs="unbounded" minOccurs="0" type="ProcessType" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Resources">
        <xs:sequence maxOccurs="unbounded">
            <xs:choice>
                <xs:element name="localStorage">
                    <xs:complexType>
                        <xs:attribute name="enabled" type="xs:boolean" use="optional" />
                        <xs:attribute name="pathKey" type="xs:string" use="required" />
                        <xs:attribute name="maximumSizeKey" type="xs:string" use="required" />
                        <xs:attribute name="configurationResourceName" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="endPoint">
                    <xs:complexType>
                        <xs:attribute name="enabled" type="xs:boolean" use="optional" />
                        <xs:attribute name="portKey" type="xs:string" use="required" />
                        <xs:attribute name="addressKey" type="xs:string" use="required" />
                        <xs:attribute name="configurationEndPointName" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="cloudDrive">
                    <xs:complexType>
                        <xs:attribute name="enabled" type="xs:boolean" use="optional" />
                        <xs:attribute name="pathKey" type="xs:string" use="required" />
                        <xs:attribute name="connectionString" type="xs:string" use="required" />
                        <xs:attribute name="pageBlobUri" type="xs:string" use="required" />
                        <xs:attribute name="readOnly" default="false" type="xs:boolean" use="optional" />
                        <xs:attribute name="copyBlob" default="true" type="xs:boolean" use="optional" />
                        <xs:attribute name="createIfNotExist" default="true" type="xs:boolean" use="optional" />
                        <xs:attribute name="createFromSourcePageBlobUri" default="false" type="xs:string" use="optional" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="blobSync">
                    <xs:complexType>
                        <xs:attribute name="enabled" type="xs:boolean" use="optional" />
                        <xs:attribute name="connectionString" type="xs:string" use="required" />
                        <xs:attribute name="blobDirectoryUri" type="xs:string" use="required" />
                        <xs:attribute name="localDirectoryPath" type="xs:string" use="required" />
                        <xs:attribute name="ignoreAdditionalFiles" default="true" type="xs:boolean" use="optional" />
                        <xs:attribute name="direction" type="xs:string" use="required" />
                        <xs:attribute name="intervalInSeconds" default="0" type="xs:int" use="optional" />
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CloudDrives">
        <xs:annotation>
            <xs:documentation>Details the list of cloud drives which should be mounted by the role.</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="22">
            <!--xs:element name="cloudDrive" type="CloudDrive" /-->
        </xs:sequence>
        <xs:attribute name="cacheSizeInMB" default="0" type="xs:int" use="optional">
            <xs:annotation>
                <xs:documentation>
                    The total amount of local storage to set aside for use in caching cloud drive content.
                    The cloud drive cache size is used by all cloud drives mounted in the instance.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="cacheLocalStorageName" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>The local storage resource name to use for the local cloud storage cache.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <xs:complexType name="Validation">
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
            <xs:element name="fileValidation" type="FileValidation" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="FileValidation">
        <xs:attribute name="enabled" type="xs:boolean" use="optional" />
        <xs:attribute name="path" type="xs:string" use="required" />
        <xs:attribute name="checkAccess" default="false" type="xs:boolean" use="optional" />
        <xs:attribute name="required" default="true" type="xs:boolean" use="optional" />
    </xs:complexType>
    <xs:complexType name="LocalCopy">
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
            <xs:element name="fileCopy" type="FileCopy" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="FileCopy">
        <xs:attribute name="enabled" type="xs:boolean" use="optional" />
        <xs:attribute name="source" type="xs:string" use="required" />
        <xs:attribute name="destination" type="xs:string" use="required" />
    </xs:complexType>
    <xs:complexType name="ProcessType">
        <xs:attribute name="enabled" type="xs:boolean" use="optional" />
        <xs:attribute name="processKey" type="xs:string" use="required" />
        <xs:attribute name="workingDir" type="xs:string" use="required" />
        <xs:attribute name="command" type="xs:string" use="required" />
        <xs:attribute name="args" default="" type="xs:string" use="optional" />
        <xs:attribute name="waitOnExit" default="true" type="xs:boolean" use="optional" />
        <xs:attribute name="waitTimeoutInSeconds" default="0" type="xs:int" use="optional" />
        <xs:attribute name="delayContinueInSeconds" default="0" type="xs:int" use="optional" />
    </xs:complexType>
    <xs:complexType name="Sites">
        <xs:annotation>
            <xs:documentation>
                A set of IIS7 sites associted with a Web Role
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="Site" type="Site" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Site">
        <xs:annotation>
            <xs:documentation>
                Defintion of a single IIS7 site associted with a Web Role
            </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="VirtualDirectory">
                <xs:sequence>
                    <xs:element name="bindings" type="Bindings"></xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="Bindings">
        <xs:annotation>
            <xs:documentation>

            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="binding" maxOccurs="unbounded" minOccurs="1" type="BindingType"></xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="BindingType">
        <xs:annotation>
            <xs:documentation>
                A site uses a list of bindings
            </xs:documentation>
        </xs:annotation>
        <xs:attribute id="name" name="name" type="NamedElementNameString" use="required">
            <xs:annotation>
                <xs:documentation>
                    The name of the binding.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute id="endpointName" name="endpointName" type="NamedElementNameString" use="required">
            <xs:annotation>
                <xs:documentation>
                    The name of the endpooint on the Web Role
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute id="hostHeader" name="hostHeader" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Host name used, if any.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="VirtualDirectory">
        <xs:sequence>
            <xs:choice maxOccurs="unbounded" minOccurs="0">
                <xs:element name="virtualDirectory" type="VirtualDirectory" />
                <xs:element name="virtualApplication" type="VirtualDirectory" />
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="virtualDirectoryName" type="VirtualDirectoryName" use="required">
            <xs:annotation>
                <xs:documentation>
                    The name which is reflected in the virtual path
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="physicalDirectory" type="PhysicalDirectoryPath" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Location of the physical directory, can also be specified during packaging.
                    A relative path is assumed to be relative to the location of the csdef.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="VirtualApplication">
        <xs:complexContent>
            <xs:extension base="VirtualDirectory" />
        </xs:complexContent>
    </xs:complexType>

    <xs:simpleType name="VirtualDirectoryName">
        <xs:restriction base="xs:string">
            <xs:pattern value="^[a-zA-Z_][^\\/\?;:\`\'\^@&amp;=\+\$,\|&quot;&lt;&gt;]*(?&lt;![\.\s])$" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="PhysicalDirectoryPath">
        <xs:restriction base="xs:string" />
    </xs:simpleType>

    <!-- 
  Allows a string which starts with alphabets or underscore, followed by any number of character
  except ^ \ / : * ? ' < > |. And it should not end in whitespace.
  -->

    <xs:simpleType name="Name">
        <xs:restriction base="NamedElementNameString" />
    </xs:simpleType>

    <xs:simpleType name="NamedElementNameString">
        <xs:restriction base="xs:string">
            <xs:pattern value="^[a-zA-Z_][^\\\/\:\*\?\&quot;\&lt;\&gt;\|\`\'\^]*(?&lt;![\.\s])$" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="NonEmptyString">
        <xs:restriction base="xs:string">
            <xs:minLength value="1" />
            <xs:maxLength value="256" />
        </xs:restriction>
    </xs:simpleType>

</xs:schema>